//
//  QueryMenuCell.m
//  PropertyMananger
//
//  Created by Mansion on 16/12/24.
//  Copyright © 2016年 BH. All rights reserved.
//

#import "QueryMenuCell.h"
#import "MenuBtnView.h"
#define TAG 300
@interface QueryMenuCell ()
{
 UIView *_backView1;
}
@end

@implementation QueryMenuCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];


}
+ (instancetype)cellWithTableView:(UITableView *)tableView menuArray:(NSArray *)menuArray
{
    static NSString * cellID = @"QueryMenuCellID";
    QueryMenuCell * toolCell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!toolCell) {
        
        toolCell = [[QueryMenuCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID menuArray:menuArray];
    }
    //选中cell的颜色 -无色
    toolCell.selectionStyle = UITableViewCellSelectionStyleNone;
    tableView.separatorStyle = NO;
    return toolCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier menuArray:(NSArray *)menuArray{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _backView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, BHscreenW, 170)];
        [self addSubview:_backView1];
//        _backView1.backgroundColor = [UIColor redColor];
        
        for (int i = 0; i < 8 ; i++) {
            
            if(i < 4) {
                
                CGRect frame = CGRectMake(i*BHscreenW/4, 0, BHscreenW/4, 84);
                NSString *title = [menuArray[i] objectForKey:@"title"];
                NSString *imagestr = [menuArray[i] objectForKey:@"image"];
                MenuBtnView *btnView = [[MenuBtnView alloc]initWithFrame:frame title:title imagestr:imagestr];
                btnView.tag = TAG + i;
                [_backView1 addSubview:btnView];
                
                //划线
                UIView * rightLine = [[UIView alloc]init];
                rightLine.frame = CGRectMake(i*BHscreenW/4, 0, 1, 84);
                [_backView1 addSubview:rightLine];
                rightLine.backgroundColor = BHGrayColor;
                //
                UIView * bottomLine = [[UIView alloc]init];
                bottomLine.frame = CGRectMake(i*BHscreenW/4,84, 103, 1);
                bottomLine.backgroundColor = BHGrayColor;
                [_backView1 addSubview:bottomLine];
                
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Clicktap:)];
                [btnView addGestureRecognizer:tap];
                
            }
            else if (i < 8) {
                
                CGRect frame = CGRectMake((i-4)*BHscreenW/4, 84, BHscreenW/4,84);
                NSString *title = [menuArray[i] objectForKey:@"title"];
                NSString *imagestr = [menuArray[i] objectForKey:@"image"];
                MenuBtnView *btnView = [[MenuBtnView alloc]initWithFrame:frame title:title imagestr:imagestr];
                btnView.tag = TAG + i;
                [_backView1 addSubview:btnView];
                
                //划线
                UIView * rightLine = [[UIView alloc]init];
                rightLine.frame = CGRectMake((i-4)*BHscreenW/4, 84, 1, 84);
                [_backView1 addSubview:rightLine];
                rightLine.backgroundColor = BHGrayColor;
                
                UIView * bottomLine = [[UIView alloc]init];
                bottomLine.frame = CGRectMake((i-4)*BHscreenW/4,168, 103, 1);
                bottomLine.backgroundColor = BHGrayColor;
                [_backView1 addSubview:bottomLine];
                
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Clicktap:)];
                [btnView addGestureRecognizer:tap];
                
            }
        }
    }
    return self;
}

#pragma mark - 点击
-(void)Clicktap:(UITapGestureRecognizer *)sender{
    
 //   NSLog(@"tag:%ld",sender.view.tag);
    
    if (self.queryBlock != nil) {
        
        self.queryBlock(sender.view.tag);
    }
}
@end
